package com.imay.live.view.custom;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.imay.live.activity.profit.ProfitHistoryActivity;
import com.imay.live.R;

/**
 * Created by Administrator on 2017/04/17 0017.
 */

public class ProfitTitle extends RelativeLayout {
    TextView tv_content;

    public ProfitTitle(Context context) {
        super(context);
        init(context);
    }

    public ProfitTitle(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
        init(context);
    }

    public ProfitTitle(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @RequiresApi(api = 21)
    public ProfitTitle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    void init(Context context) {
        View view = new View(context);
        LayoutParams viewparams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2);
        view.setBackgroundColor(Color.argb(51,255,255,255));
        viewparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        view.setId(R.id.profitview_id);
        addView(view, viewparams);

        ImageView imageView = new ImageView(context);
        imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.btn_05chongzhi_help_3));
        LayoutParams imageViewparams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        imageViewparams.addRule(RelativeLayout.BELOW, view.getId());
        imageViewparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        imageViewparams.rightMargin = (int) getResources().getDimension(R.dimen.profitiv_top);
        imageViewparams.topMargin = (int) getResources().getDimension(R.dimen.profitiv_right);
        addView(imageView, imageViewparams);
        imageView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ProfitHistoryActivity.startActivity(getContext());
            }
        });
        TextView tv_title = new TextView(context);
        tv_title.setId(R.id.profittitle_id);
        tv_title.setText(getResources().getString(R.string.exchange_profit));
        tv_title.setTextColor(Color.WHITE);
        LayoutParams paramst = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        paramst.topMargin = (int) getResources().getDimension(R.dimen.title_top);
        paramst.bottomMargin = (int) getResources().getDimension(R.dimen.title_bottom);
        tv_title.setGravity(Gravity.CENTER);
        paramst.addRule(RelativeLayout.BELOW, view.getId());
        addView(tv_title, paramst);
        tv_content = new TextView(context);
        tv_content.setTextColor(Color.WHITE);
        tv_content.setGravity(Gravity.CENTER);
        tv_content.setTextSize(51);
        LayoutParams paramsc = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        paramsc.topMargin = (int) getResources().getDimension(R.dimen.title_bottom);
        paramsc.bottomMargin = (int) getResources().getDimension(R.dimen.title_top);
        paramsc.addRule(RelativeLayout.BELOW, tv_title.getId());
        addView(tv_content, paramsc);
    }

    public void setText(CharSequence text) {
        tv_content.setText(text);
    }
    public String getTextString() {
        return tv_content.getText().toString();
    }
}
